Repository navigation
More consistent checks for captured types - #1662
Conversation
|
This change is part of the following stack: Change managed by git-spice. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1662 +/- ##
============================================
+ Coverage 87.73% 87.75% +0.02%
- Complexity 3130 3132 +2
============================================
Files 109 109
Lines 10579 10580 +1
Branches 2137 2136 -1
============================================
+ Hits 9281 9285 +4
+ Misses 616 615 -1
+ Partials 682 680 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Walkthrough
Possibly related issues
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@nullaway/src/test/java/com/uber/nullaway/jspecify/WildcardTests.java`:
- Around line 906-980: Add concise Javadoc immediately above the three new
public test methods: capturedSuperWildcardReturnCheckedForContainment should
document direct wildcard containment checking,
capturedSuperWildcardReturnCheckedRecursively should document recursive nested
containment checking, and capturedLhsWithFBoundedTypeParametersDoesNotRecurse
should document that F-bounded type parameters must not trigger recursive
analysis.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 6194c562-6f3f-4a5a-b781-6108bbcc2b1b
📒 Files selected for processing (2)
nullaway/src/main/java/com/uber/nullaway/generics/CheckIdenticalNullabilityVisitor.javanullaway/src/test/java/com/uber/nullaway/jspecify/WildcardTests.java
| @Test | ||
| public void capturedSuperWildcardReturnCheckedForContainment() { | ||
| makeHelper() | ||
| .addSourceLines( | ||
| "Test.java", | ||
| """ | ||
| import org.jspecify.annotations.NullMarked; | ||
| import org.jspecify.annotations.Nullable; | ||
| @NullMarked | ||
| class Test { | ||
| interface Box<T extends @Nullable Object> {} | ||
| static <T extends @Nullable Object> Box<T> identity(Box<T> box) { | ||
| return box; | ||
| } | ||
| void test( | ||
| Box<? super String> nonNullBoundBox, | ||
| Box<? super @Nullable String> nullableBoundBox) { | ||
| Box<? super String> ok = identity(nullableBoundBox); | ||
| // BUG: Diagnostic contains: incompatible types | ||
| Box<? super @Nullable String> bad = identity(nonNullBoundBox); | ||
| } | ||
| } | ||
| """) | ||
| .doTest(); | ||
| } | ||
|
|
||
| @Test | ||
| public void capturedSuperWildcardReturnCheckedRecursively() { | ||
| makeHelper() | ||
| .addSourceLines( | ||
| "Test.java", | ||
| """ | ||
| import org.jspecify.annotations.NullMarked; | ||
| import org.jspecify.annotations.Nullable; | ||
| @NullMarked | ||
| class Test { | ||
| interface Box<T extends @Nullable Object> {} | ||
| interface Nested<T extends @Nullable Object> {} | ||
| static <T extends @Nullable Object> Box<T> identity(Box<T> box) { | ||
| return box; | ||
| } | ||
| void test(Box<? super Nested<String>> box) { | ||
| // BUG: Diagnostic contains: incompatible types | ||
| Box<? super Nested<@Nullable String>> bad = identity(box); | ||
| } | ||
| } | ||
| """) | ||
| .doTest(); | ||
| } | ||
|
|
||
| @Test | ||
| public void capturedLhsWithFBoundedTypeParametersDoesNotRecurse() { | ||
| makeHelper() | ||
| .addSourceLines( | ||
| "Test.java", | ||
| """ | ||
| import org.jspecify.annotations.NullMarked; | ||
| @NullMarked | ||
| class Test { | ||
| interface Value<V extends Value<V>> {} | ||
| interface Store<S extends Store<S>> {} | ||
| interface Transfer<V extends Value<V>, S extends Store<S>> {} | ||
| static class Analysis< | ||
| V extends Value<V>, | ||
| S extends Store<S>, | ||
| T extends Transfer<V, S>> { | ||
| Analysis(T transfer) {} | ||
| } | ||
| static Analysis<?, ?, ?> create(Transfer<?, ?> transfer) { | ||
| return new Analysis<>(transfer); | ||
| } | ||
| } | ||
| """) | ||
| .doTest(); | ||
| } |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Add Javadoc for the new regression tests.
Document the direct containment, recursive containment, and F-bounded recursion scenarios in the three new public test methods. As per coding guidelines, “Add Javadoc to every non-trivial method, including private methods.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@nullaway/src/test/java/com/uber/nullaway/jspecify/WildcardTests.java` around
lines 906 - 980, Add concise Javadoc immediately above the three new public test
methods: capturedSuperWildcardReturnCheckedForContainment should document direct
wildcard containment checking, capturedSuperWildcardReturnCheckedRecursively
should document recursive nested containment checking, and
capturedLhsWithFBoundedTypeParametersDoesNotRecurse should document that
F-bounded type parameters must not trigger recursive analysis.
Source: Coding guidelines
This PR addresses this sub-issue of #1656:
The fix is to consistently call
GenericsUtils.asWildcard, which handles bothWildcardTypeandCapturedType, when checking if a type is a wildcard.The new tests show subtyping issues that weren't identified before that are caught with these fixes.
Summary by CodeRabbit
Bug Fixes
superwildcards.Tests